package com.sofwin.ruoyi.scyffinal.controller;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.sofwin.ruoyi.scyffinal.pojo.ScyfFinalOnSiteEmergency;
import com.sofwin.ruoyi.scyffinal.service.ScyfSiteEmergencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/emergency")
public class ScyfFinalOnSiteEmergencyController extends BaseController {

    @Autowired
    private ScyfSiteEmergencyService scyfSiteEmergencyService;

    /**
     * 查询所有的紧急处置卡，并且根据查询条件显示对应的处置卡
     *
     * @param scyfFinalOnSiteEmergency 需要查询处置卡的信息
     * @return 处置卡集合
     */

    @GetMapping("/list")
    public List<ScyfFinalOnSiteEmergency> list(ScyfFinalOnSiteEmergency scyfFinalOnSiteEmergency) {
        startPage();
        List<ScyfFinalOnSiteEmergency> scyfFinalOnSiteEmergencies = scyfSiteEmergencyService.selectScyfSiteEmergencyList(scyfFinalOnSiteEmergency);
        System.out.println(scyfFinalOnSiteEmergencies);
        return scyfFinalOnSiteEmergencies;
    }

    /**
     * 获取客户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(scyfSiteEmergencyService.selectScyfFinalOnSiteEmergencyById(id));
    }

    /**
     * 导出所有的处置卡
     *
     * @param response                 响应对象
     * @param scyfFinalOnSiteEmergency 处置卡信息
     */
    @Log(title = "紧急处置卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScyfFinalOnSiteEmergency scyfFinalOnSiteEmergency) {
        List<ScyfFinalOnSiteEmergency> list = scyfSiteEmergencyService.selectScyfSiteEmergencyList(scyfFinalOnSiteEmergency);

        // 添加调试信息
        System.out.println("导出数据数量: " + list.size());
        System.out.println("查询参数: " + scyfFinalOnSiteEmergency);

        ExcelUtil<ScyfFinalOnSiteEmergency> util = new ExcelUtil<>(ScyfFinalOnSiteEmergency.class);
        util.exportExcel(response, list, "紧急处置卡数据");
    }

    /**
     * 新增处置卡
     *
     * @param scyfFinalOnSiteEmergency 处置卡信息
     * @return
     */
    @Log(title = "紧急处置卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScyfFinalOnSiteEmergency scyfFinalOnSiteEmergency) {
        return toAjax(scyfSiteEmergencyService.insertScyfSiteEmergency(scyfFinalOnSiteEmergency));
    }

    /**
     * 修改处置卡
     *
     * @param scyfFinalOnSiteEmergency 处置卡信息
     * @return
     */
    @Log(title = "紧急处置卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScyfFinalOnSiteEmergency scyfFinalOnSiteEmergency) {
        return toAjax(scyfSiteEmergencyService.updateScyfSiteEmergency(scyfFinalOnSiteEmergency));
    }

    /**
     * 删除处置卡
     *
     * @param ids 需要删除的处置卡ID
     * @return
     */
    @Log(title = "紧急处置卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(scyfSiteEmergencyService.deleteScyfSiteEmergencyByIds(ids));
    }

}
